<!DOCTYPE html>
<html>
<head>
    {include file="public/head"}
</head>
<body>
<div class="g-flexview">
    <header class="m-navbar">
        <a href="javascript:history.back();" class="navbar-item">
            <i class="back-ico"></i>
        </a>
        <div class="navbar-center"><span class="navbar-title">购买</span></div>
    </header>
    <div class="g-scrollview">
        <div class="m-cell">
            <div class="cell-item">
                <div class="cell-left">创建人</div>
                <div class="cell-right">{:getInfo($orderInfo['user_id'])['nickname']}</div>
            </div>
            <div class="cell-item">
                <div class="cell-left">HX币</div>
                <div class="cell-right">{$orderInfo['money']}个</div>
            </div>
            <div class="cell-item">
                <div class="cell-left">单价</div>
                <div class="cell-right">￥{$orderInfo['unit_price']}</div>
            </div>
            <div class="cell-item">
                <div class="cell-left">总金额</div>
                <div class="cell-right">￥{$orderInfo['unit_price']*$orderInfo['money']}</div>
            </div>
            <div class="cell-item">
                <div class="cell-left">时间</div>
                <div class="cell-right">{$orderInfo['add_time']|date="Y-m-d H:is",###}</div>
            </div>
        </div>
    </div>
    <button type="button" class="btn-block btn-primary" id="J_OpenKeyBoard">立即购买</button>
</div>
{include file="public/js"}
<script>
    !function ($) {
        //
    }(jQuery);
</script>
<div class="m-keyboard" id="J_KeyBoard">
    <!-- 自定义内容区域 -->
    <div style="text-align: right;padding: .15rem .8rem 0;">
        <a href="/index/set/tradePassword.html" style="color: #666;font-size: .24rem;">忘记密码？</a>
    </div>
    <!-- 自定义内容区域 -->
</div>
<script>
    // 安全键盘
    var $keyboard = $('#J_KeyBoard');

    /* 初始化参数 */
    $keyboard.keyBoard({
        disorder: false, /* 是否打乱数字顺序 */
        title: '华兴交易密码' /* 显示标题 */
    });
    /* 打开键盘 */
    $('#J_OpenKeyBoard').on('click', function () {
        $keyboard.keyBoard('open');
    });
    /* 六位密码输入完毕后执行 */
    $keyboard.on('done.ydui.keyboard', function (ret) {
        //console.log('输入的密码是：' + ret.password);
        YDUI.dialog.loading.open('验证支付密码');
        $.post('/index/trade/buy',{id : '{$orderInfo["id"]}','trade_password' : ret.password},function (res) {
            if (res.code == -1){ /* 显示错误信息 */
                YDUI.dialog.loading.close();
                $keyboard.keyBoard('error', '对不起，您的支付密码不正确，请重新输入。');
                return '';
            }
            YDUI.dialog.loading.close();
            $keyboard.keyBoard('close');/* 关闭键盘 */
            dialog.toast(res.msg,'none',1000,function () {
                if (res.code == 1){
                    $.post('/api/sms/sellTip',{phone : "{$orderInfo['user_phone']}"},function (res) {
                        location.href='/index/trade/index';
                    });
                }
            });
        });
    });
</script>
</body>
</html>